<template>
    <div>
        <TableSearch :query="query" :options="searchOpt" :search="handleSearch" />
        <div class="container">

            <TableCustom :columns="columns" :tableData="tableData" :total="page.total" :viewFunc="handleView"
                :delFunc="handleDelete" :changePage="changePage" :editFunc="handleEdit">
                <template #toolbarBtn>
                    <el-button type="warning" :icon="CirclePlusFilled" @click="visible = true">发起提现</el-button>
                </template>
                <template #status="{ rows }">
                    <el-tag type="success" v-if="rows.status">启用</el-tag>
                    <el-tag type="danger" v-else>禁用</el-tag>
                </template>

            </TableCustom>
        </div>
        <el-dialog title="发起提现" v-model="visible" width="300px" destroy-on-close :close-on-click-modal="false"
            @close="closeDialog">
            <div class="salePrice">
                <span>钱包地址 ：</span> <el-input v-model="wallet.trc" />
            </div>
            <div class="salePrice">
                <span>谷歌验证码 ：</span> <el-input v-model="wallet.google_code" />
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submit">
                        确定
                    </el-button>
                </div>
            </template>
        </el-dialog>


    </div>
</template>

<script setup lang="ts">
    import { ref, reactive } from 'vue';
    import { ElMessage } from 'element-plus';
    import { Role } from '@/types/role';
    import { agentWithdrawList, agentWithdraw } from '@/api';
    import TableCustom from '@/components/table-custom.vue';
    import TableDetail from '@/components/table-detail.vue';
    import { CirclePlusFilled } from '@element-plus/icons-vue';
    import { FormOption, FormOptionList } from '@/types/form-option';

    // 查询相关
    const query = reactive({
        no: '',
    });
    const searchOpt = ref < FormOptionList[] > ([
        { type: 'input', label: '订单号:', prop: 'no' }
    ])
    const handleSearch = () => {
        page.no = query.no
        changePage(1);
    };
    let wallet = ref({
        trc: '',
        google_code: ''
    })
    // 表格相关
    let columns = ref([
        { prop: 'no', label: '提现订单号', width: 220 },
        { prop: 'trc', label: '钱包地址', width: 140 },
        { prop: 'money', label: '金额' },
        { prop: 'status', label: '状态' },
        { prop: 'reason', label: '原因', },
        { prop: 'createtime', label: '创建时间', width: 160 },
        { prop: 'updatetime', label: '更新时间', width: 160 },
    ])
    const page = reactive({
        page: 1,
        limit: 10,
        total: 0,
        no: ''
    })
    const tableData = ref < Role[] > ([]);
    const getData = async () => {
        const res = await agentWithdrawList(page)
        tableData.value = res.data.data;
        page.total = res.data.total
    };
    getData();
    const changePage = (val: number) => {
        page.page = val;
        getData();
    };

    // 新增/编辑弹窗相关
    const options = ref < FormOption > ({
        labelWidth: '100px',
        span: 24,
        list: [
            { type: 'input', label: '角色名称', prop: 'name', required: true },
            { type: 'input', label: '角色标识', prop: 'key', required: true },
            { type: 'switch', label: '状态', prop: 'status', required: false, activeText: '启用', inactiveText: '禁用' },
        ]
    })
    const visible = ref(false);
    const isEdit = ref(false);
    const rowData = ref({});
    const handleEdit = (row: Role) => {
        rowData.value = { ...row };
        isEdit.value = true;
        visible.value = true;
    };
    const updateData = () => {
        closeDialog();
        getData();
    };
    const submit = async () => {
        let res = await agentWithdraw(wallet.value)
        if (res.code == 1) {
            visible.value = false
            wallet.value.trc = ''
            ElMessage.success(res.msg);
        }

    }
    const closeDialog = () => {
        visible.value = false;
        wallet.value.trc = ''
        wallet.value.google_code = ''

    };

    // 查看详情弹窗相关
    const visible1 = ref(false);
    const viewData = ref({
        row: {},
        list: [],
        column: 1
    });
    const handleView = (row: Role) => {
        viewData.value.row = { ...row }
        viewData.value.list = [
            {
                prop: 'id',
                label: '角色ID',
            },
            {
                prop: 'name',
                label: '角色名称',
            },
            {
                prop: 'key',
                label: '角色标识',
            },
            {
                prop: 'status',
                label: '角色状态',
            },
        ]
        visible1.value = true;
    };

    // 删除相关
    const handleDelete = (row: Role) => {
        ElMessage.success('删除成功');
    }


    // 权限管理弹窗相关
    const visible2 = ref(false);
    const permissOptions = ref({})
    const handlePermission = (row: Role) => {
        visible2.value = true;
        permissOptions.value = {
            id: row.id,
            permiss: row.permiss
        };
    }
</script>

<style scoped>
    .salePrice {

        margin: 26px 0;
    }
</style>